﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace CTEA_INDIA
{
    public partial class Candidate_Registration : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["CTEA"].ConnectionString;
            if (Session["UserID"] != null)
            {

              //  Response.Redirect("Default.aspx");
            }
            if (!IsPostBack)
            {
                BAL.Customers.PopulateCategory(ref ddlApplyFor);
                BAL.Customers.PopulateLocation(ref ddlLocation);

            }
        }
        protected void IsNotFutureDate(object sender, ServerValidateEventArgs args)
        {
            DateTime dt;

            bool IsDate = DateTime.TryParse(args.Value.ToString(), out dt);

            if (IsDate)
            {
                if (dt.Date <= DateTime.Now.Date)
                    args.IsValid = true;
                else
                    args.IsValid = false;

            }

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            string Email = txtEmailId.Text;

            int strVal = BAL.Customers.verifyuser(Email, "", 1);
            if (strVal == -1)
            {

                if (Page.IsValid)
                {
                    string EmailID = txtEmailId.Text;
                    string Password = txtPass.Text;

                    string EncryptedPass = BAL.Encryption.Encript(Password, "&%#@?,:*");
                    string DecryptedPassword = BAL.Encryption.Decrypt(EncryptedPass, "&%#@?,:*");
                    string Name = txtName.Text;
                    string Gender = rbtGender.SelectedValue;
                    DateTime DateOfBirth = Convert.ToDateTime(txtDOB.Text);
                    string Address = txtAddress.Text;
                    string Location =  ddlLocation.SelectedValue ;
                    string Mobileno = txtPers_MobileNo.Text;
                    string Education = txtEducation.Text;
                    string Qualification = txtQualification.Text;
                    string ApplyFor = ddlApplyFor.SelectedValue;
                    string Guardian_name = txtGuardian_Name.Text;
                    string Guardian_Cno = txtGuardian_Cno.Text;
                    string Guardian_Location = txtGuardian_Locaton.Text;
                    string Relationshp = txtRelationshp.Text;
                    string filename = ftpProfpic.FileName;
                    string howKnow = txtHow_Approched.Text;
                    string Occu = txtOccup.Text;
                    string ArtistId = txtArtistID.Text;



                    int UserId = BAL.Customers.CandidateRegistration(EmailID, EncryptedPass, Name, Gender, DateOfBirth, Address,
                        Location, Mobileno, Education, Qualification, ApplyFor, Guardian_name, Guardian_Cno, Guardian_Location, Relationshp, filename, howKnow, Occu, ArtistId);

                    ftpProfpic .SaveAs(Server.MapPath("ProfilePhoto/" + filename));

                txtEmailId.Text="";
                txtPass.Text = "";

                   // string EncryptedPass = BAL.Encryption.Encript(Password, "&%#@?,:*");
                    //string DecryptedPassword = BAL.Encryption.Decrypt(EncryptedPass, "&%#@?,:*");
                txtName.Text = "";
                rbtGender.SelectedValue = "";
                   // DateTime DateOfBirth = Convert.ToDateTime(txtDOB.Text);
                txtAddress.Text = "";
                   //  ddlLocation.SelectedValue;
                txtPers_MobileNo.Text = ""; 
                txtEducation.Text = "";
                txtQualification.Text = "";
                       
                     txtGuardian_Name.Text="";
                     txtGuardian_Cno.Text = "";
                     txtGuardian_Locaton.Text = "";
                     txtRelationshp.Text = "";
                   // string filename = ftpProfpic.FileName;
                     txtHow_Approched.Text = "";
                     txtOccup.Text = "";
                     txtArtistID.Text = "";

















                    Response.Redirect("Confirmation.aspx");
                    //errSpan.Visible = true;
                    //errSpan.Style.Add("background-color", "#fff");
                    //errSpan.Style.Add("color", "green");
                    //errSpan.InnerHtml = "Your registration completed successfully.";

                    String StrCon = "<div style=\"margin-left:20px;\">" +
                             "<span style=\"font-size: 12px; font-family: 'CENTURY GOTHIC'\">" +
                             "<br>Dear <b>" + Name + "</b>,<br><br>" +
                             "Welcome to <b>CTEA INDIA </b><br><br>" +
                             "We are pleased to welcome you to CTEA INDIA.<br> Thank you for registered with us." +
                             "<br><br>Best Regards,<br>CTEA INDIA Team" +
                             "<br><a href=\"http://www.CTEAINDIA.in\">www.CTEAINDIA.in</a></span><br><br><img src=\"cid:companylogo\"></div>";
                    BAL.Common.SendEmail("", EmailID, "Notification from CTEA India", StrCon);
                    BAL.Customers.SendUserDetails(EmailID, DecryptedPassword);



                }
             
            }
            else
            {
                errSpan.Visible = true;
                errSpan.InnerHtml = "Your Email ID already exist.";
            }
        }
    }
}
